//
//  RAPStatusModel.swift
//  COPYCAT-Weibo
//
//  Created by 闫萌 on 1/1/16.
//  Copyright © 2016 RendezvousAuParadis. All rights reserved.
//

import UIKit

class RAPStatusModel: NSObject {
    /** 微博创建时间 */
    var created_at: String?
    /** 微博信息内容 */
    var text: String?
    /** 微博来源 */
    var source: String?
    /** reposts_count	int	转发数 */
    var reposts_count: Int = 0
    /** comments_count	int	评论数 */
    var comments_count: Int = 0
    /** attitudes_count	int	表态数 */
    var attitudes_count: Int = 0
    /** retweeted_status	object	被转发的原微博信息字段，当该微博为转发微博时返回 */
    var retweeted_status: RAPStatusModel?
    /** user	object	微博作者的用户信息字段 */
    var user: RAPUserModel?
    /** pic_urls	微博配图数组 */
    var pic_urls: [RAPStatusPictureModel]?
    /** id 微博id */
    var id: Int64 = 0
    
    init(dict: [String : AnyObject]) {
        super.init()
        
        setValuesForKeysWithDictionary(dict)
    }
}

extension RAPStatusModel {
    
    override func setValue(value: AnyObject?, forKey key: String) {
        if key == "user" {
            /*
            如果key为user，则将value（字典）利用kvc转换为RAPUserModel模型，并赋给user属性
            */
            user = RAPUserModel(dict: value as! [String : AnyObject])
        } else if key == "retweeted_status" {
            retweeted_status = RAPStatusModel(dict: value as! [String : AnyObject])
        } else if key == "pic_urls" { // 如果是配图
            let picArr = value as! [[String : String]]
            pic_urls = [RAPStatusPictureModel]()
            for dict in picArr {
                let statusPictureModel = RAPStatusPictureModel(dict: dict)
                pic_urls?.append(statusPictureModel)
                
            }
        } else {
            super.setValue(value, forKey: key)
        }
    }
    
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {
        // 留空
    }
    
    
//    override var description: String {
//        let descDict = dictionaryWithValuesForKeys(["statusModel"])
//        return descDict.description
//    }
}
